/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2006，所有权利保留。
 * 
 * 文件名：	FVRumbaSystem.java
 * 模块说明：	
 * 修改历史：
 * 2006-10-25 - lxm - 创建。
 */
package com.hd123.rumba.cartridge;

import net.sf.hibernate.HibernateException;

import com.hd123.rumba.action.organization.ViewOrganizationSystem;
import com.hd123.rumba.action.user.ViewRoleSystem;
import com.hd123.rumba.action.user.ViewUserSystem;
import com.hd123.rumba.cartridge.biz.BCartFunctionView;
import com.hd123.rumba.cartridge.entry.Entry;
import com.hd123.rumba.domain.CDomain;
import com.hd123.rumba.domain.IDomain;
import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.navigation.menu.BMenu;
import com.hd123.rumba.navigation.menu.BMenuItem;
import com.hd123.rumba.organization.COrganization;
import com.hd123.rumba.user.CRole;
import com.hd123.rumba.user.CUser;
import com.hd123.rumba.user.IUser;

/**
 * 功能视图：系统管理
 * <p>
 * 
 * 标题：系统管理<br>
 * 前缀：RBS<br>
 * 抽象：否<br>
 * 说明：提供一般域用户关于组织、域、以及用户认证与授权等功能的操作界面。<br>
 * 依赖：FVRumbaSystemCommon<br>
 * 
 * @author lxm
 * 
 */
public class FVRumbaSystem extends BCartFunctionView {

  public static final String FUNCV_PREFIX = "RBS";

  @Override
  public boolean canLoadToDomain(IDomain domain) throws BusinessException, HibernateException {
    return !CDomain.VALUE_ID_ROOT.equals(domain.getCode());
  }

  @Override
  public void onLoadToDomain(IDomain domain, IUser operator) throws BusinessException,
      HibernateException, InterruptedException {
    // Do Nothing
  }

  @Override
  public void onUnloadFromDomain(IDomain domain, IUser operator) throws BusinessException,
      HibernateException, InterruptedException {
    // Do Nothing
  }
  
  public static final String ID_ENTRY_MYORGANIZATION = "myOrganization";
  public static final String ID_ENTRY_MYLOWERORGS = "myLowerOrgs";
  public static final String ID_ENTRY_MYBROTHERORGS = "myBrotherOrgs";
  public static final String ID_ENTRY_USER = "user";
  public static final String ID_ENTRY_ROLE = "role";

  @Override
  protected void buildEntries() throws BusinessException {
    this.getEntries().clear();
    Entry e = null;
    
    e = this.appendEntry(ID_ENTRY_MYORGANIZATION, "我的" + COrganization.CAPTION_CLASS);
    e.setPermission(ViewOrganizationSystem.PERMISSION_SELF_VIEW);
    e.setImage("rumba/images/organization/org_small.gif");
    e.appendLink("organization/ViewOrganizationSystem?start=home");
    
    e = this.appendEntry(ID_ENTRY_MYLOWERORGS, "下级" + COrganization.CAPTION_CLASS);
    e.setPermission(ViewOrganizationSystem.PERMISSION_LOWER_VIEW);
    e.setImage("rumba/images/organization/org_small.gif");
    e.appendLink("organization/ViewOrganizationSystem?start=myLowerOrgs");
    
    e = this.appendEntry(ID_ENTRY_MYBROTHERORGS, "兄弟" + COrganization.CAPTION_CLASS);
    e.setPermission(ViewOrganizationSystem.PERMISSION_BROTHER_VIEW);
    e.setImage("rumba/images/organization/org_small.gif");
    e.appendLink("organization/ViewOrganizationSystem?start=myBrotherOrgs");
    
    e = this.appendEntry(ID_ENTRY_USER, CUser.CAPTION_CLASS);
    e.setPermission(ViewUserSystem.PERMISSION_VIEW);
    e.setImage("rumba/images/user/user_small.gif");
    e.appendLink("user/ViewUserSystem?start=list");
    
    e = this.appendEntry(ID_ENTRY_ROLE, CRole.CAPTION_CLASS);
    e.setPermission(ViewRoleSystem.PERMISSION_VIEW);
    e.setImage("rumba/images/user/role_small.gif");
    e.appendLink("user/ViewRoleSystem?start=list");
  }

  @Override
  protected void buildMainMenu(BMenu mainMenu) throws BusinessException {
    BMenuItem miSystem = BMenuItem.build(null, "系统", null);
    mainMenu.addItem(miSystem, null);

    BMenuItem miOrgDomain = BMenuItem.build(null, COrganization.CAPTION_CLASS + "与"
        + CDomain.CAPTION_CLASS, null);
    mainMenu.addItem(miOrgDomain, miSystem);
    mainMenu.addItem(BMenuItem.build(this.getEntryById(ID_ENTRY_MYORGANIZATION)), miOrgDomain);
    mainMenu.addItem(BMenuItem.build(this.getEntryById(ID_ENTRY_MYLOWERORGS)), miOrgDomain);
    mainMenu.addItem(BMenuItem.build(this.getEntryById(ID_ENTRY_MYBROTHERORGS)), miOrgDomain);

    BMenuItem miUserMgr = BMenuItem.build(null, CUser.CAPTION_CLASS + "管理", null);
    mainMenu.addItem(miUserMgr, miSystem);
    mainMenu.addItem(BMenuItem.build(this.getEntryById(ID_ENTRY_USER)), miUserMgr);
    mainMenu.addItem(BMenuItem.build(this.getEntryById(ID_ENTRY_ROLE)), miUserMgr);

    BMenuItem miLogMgr = BMenuItem.build(null, "日志管理", null);
    mainMenu.addItem(miLogMgr, miSystem);
    mainMenu.addItem(BMenuItem.build(this.getEntryById(FVRumbaSystemCommon.class,
        FVRumbaSystemCommon.ID_ENTRY_LOG)), miLogMgr);
  }
}
